package cn.ruanyun.backInterface.modules.business.profitDetail.controller;

import cn.ruanyun.backInterface.common.utils.PageUtil;
import cn.ruanyun.backInterface.common.utils.ResultUtil;
import cn.ruanyun.backInterface.common.vo.PageVo;
import cn.ruanyun.backInterface.common.vo.Result;
import cn.ruanyun.backInterface.modules.base.pojo.DataVo;
import cn.ruanyun.backInterface.modules.business.profitDetail.service.IProfitDetailService;
import cn.ruanyun.backInterface.modules.business.profitDetail.vo.ProfitDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * @author z
 * 分红明细管理接口
 */
@Slf4j
@RestController
@RequestMapping("/ruanyun/profitDetail")
@Transactional
@Api(tags = "资金流向")
public class ProfitDetailController {

    @Autowired
    private IProfitDetailService iProfitDetailService;


    /**
     * 获取资金流向信息
     * @param pageVo pageVo
     * @return Object
     */
    @PostMapping("/getProfitDetailList")
    public Result<Object> getProfitDetailList(PageVo pageVo) {

        return Optional.ofNullable(iProfitDetailService.getProfitDetailList())
                .map(profitDetailVos -> {

                    DataVo<ProfitDetailVo> result = new DataVo<>();
                    result.setTotalNumber(profitDetailVos.size())
                            .setDataResult(PageUtil.listToPage(pageVo, profitDetailVos));

                    return new ResultUtil<>().setData(result, "获取资金流向信息成功！");
                }).orElse(new ResultUtil<>().setErrorMsg(201, "暂无数据！"));

    }


    @PostMapping("/getStoreIncomeCount")
    @ApiOperation("互殴平台统计收入")
    public Result<Object> getPlatformIncomeCount() {

        return new ResultUtil<>().setData(iProfitDetailService.getProfitDetailVo(), "获取平台统计收入数据成功！");
    }

}
